
local StageCtrl={}

function StageCtrl:init()
    print("StageCtrl init")
    NetEngine:registerCallback(ProtoCmd.ResPlayerWalkMessage,function(msg)
        MapController:actorGoTo(msg.id,cc.p(msg.x,msg.y))
    end)
    NetEngine:registerCallback(ProtoCmd.ResEnterViewMessage,function(msg)
        DyActor:addProtoActors(msg.actor)
        --FzEventCenter:DispichEvent(FzEvent.addActors)
    end)
    NetEngine:registerCallback(ProtoCmd.ResExitViewMessage,function(msg)
        DyActor:removeActor(msg.id)
        MapController:removeActor(msg.id)
        --FzEventCenter:DispichEvent(FzEvent.removeActors)
    end)
    NetEngine:registerCallback(ProtoCmd.ResChangeStageMessage,function(msg)
        if msg.id == RoleData.player_info.rid then
            RoleData.player_info.stageid = msg.stageid
            RoleData.player_info.pos.x = msg.x 
            RoleData.player_info.pos.y = msg.y
            FzEventCenter:DispichEvent(FzEvent.SwitchMap)
        end
         
    end)
    NetEngine:registerCallback(ProtoCmd.ResChangePosMessage,function(msg)
        MapController:ChangePos(msg.id,{x=msg.x,y=msg.y},msg.dir)
    end)
end

function StageCtrl:clean()
    NetEngine:unregisterCallback(ProtoCmd.ResPlayerWalkMessage)
    NetEngine:unregisterCallback(ProtoCmd.ResChangeStageMessage)
end

return StageCtrl